define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-edit").data("area", ["100%", "100%"]);//编辑
            $(".btn-add").data("area", ["100%", "100%"]); //添加
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_info/index' + location.search,
                    add_url: 'user/user_info/add',
                    edit_url: 'user/user_info/edit',
                    del_url: 'user/user_info/del',
                    multi_url: 'user/user_info/multi',
                    import_url: 'user/user_info/import',
                    table: 'user_info',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'id_cards', title: __('Id_cards'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sex', title: __('Sex'),
                            searchList: {1:__('Sex 1'), 2: __('Sex 2')},
                            formatter: Table.api.formatter.flag
                        },
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'wechat_number', title: __('Wechat_number')},
                        {field: 'city', title: __('City'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'identity', title: __('Identity'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'topic', title: __('Topic'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'industry', title: __('Industry'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_rz', title: __('Is_rz'),
                            searchList: {1:__('Is_rz 1'), 2: __('Is_rz 2'), 3: __('Is_rz 3')},
                            formatter: Table.api.formatter.flag
                        },
                        {field: 'enclosure', title: __('Enclosure'), operate: false, formatter: Table.api.formatter.url},
                        {field: 'enclosure_name', title: __('Enclosure_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'),
                            searchList: {1:__('Status 1'), 2: __('Status 2')},
                            formatter: Table.api.formatter.flag
                        },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('资质列表'),
                                    title: __('资质列表'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    extend: 'data-area=\'["100%","100%"]\'',
                                    url: 'user/user_info/list',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            table.on('post-body.bs.table', function () {
                $(".btn-editone").data("area", ["100%", "100%"]);
                $(".btn-addone").data("area", ["100%", "100%"]);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        qualifications: function () {
            Controller.api.bindevent();
        },
        list: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user_info/list' + location.search + '&ids=' + Fast.api.query('ids'),
                    add_url: 'user/user_info/qualifications?ids=' + Fast.api.query('ids'),
                    edit_url: 'user/user_info/updates',
                    del_url: 'user/user_info/deletes',
                    table: 'offline_information',
                }
            });
            var tables = $("#tables");
            // 初始化表格
            tables.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('资质名称')},
                        {field: 'path', title: __('资质路径'), operate: false, formatter: Table.api.formatter.url},
                        {field: 'path_file_names', title: __('上传的资质文件名称')},
                        {field: 'status', title: __('资质状态'),
                            searchList: {1:__('待审核'), 2: __('审核通过'), 3: __('审核驳回')},
                            formatter: Table.api.formatter.flag
                        },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: tables, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(tables);
        },
        updates: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
